<?php
/**
 * 用户相关操作控制器，包括用户的注册、登录、修改密码等
 * @author:zhulin
 * @since:2012 5.4
 */
class UserController extends BaseController{
   /**
     *  用户注册接口
     * return array(
     * <pre>
     *          UName     string      用户名称
     *          UId       int         用户唯一ID
     *          Passwd    string      用户注册密码
     *          BirthDay  datetime    用户出生日期
     *          Phone     int         用户注册手机号
     *          EmaiL    string       用户注册邮箱
     *         
     * </pre>
     * )
     */
    public function register() {
        //用户注册相关参数
        $username = $this->getParamString('username');
        $passwd = $this->getParamString('passwd');

        
        //注册用户，返回用户详细信息
         $userInfo = User_Info::userRegister($username, $passwd );

        $_SESSION['UId']   = $userInfo['UID'];
        $_SESSION['UName'] = $userInfo['UName'];

        Helper_Url::redirect('index.php');
    }
    /**
     * 用户登录接口
     * @param string Uname     用户名
     * @param string Password  密码
     * @return array
     * <pre>
     *  array(
     *      UId:int
     *      UName:string
     *      Password:string
     *  )
     * </pre>
     */
    public function login() {
        //登录验证 
        
        $username = $this->getParamString('username');
       
        $password = $this->getParamString('password');
        //加密密码   
        $key = Common::getConfig('passEncrypt');
        $passwdHash = Helper_String::password_hash($password, $key);
        
        $userInfo = User_Info::getUserInfo($username, $passwdHash);
        if (empty($userInfo)) {

            throw new AppException(3001);
        }
        $_SESSION['UName'] = $userInfo['UName'];
        $_SESSION['UId'] = $userInfo['UId'];
       
        Helper_Url::redirect('index.php');
    }
    /**
     * 登出接口，清空用户的设备信息+2.
     * @return array
     * <pre>
     *  array(
     *      userInfo:UserInfo_Info
     *  )
     * </pre>
     */
    public function loginout()
    { 

        unset($_SESSION['UId']);
        unset($_SESSION['UName']);
        Helper_Url::redirect('index.php');
    }
    /*
     * 高级用户注册
     */
    public function powerRegister(){
        $email = $this->getParamString( 'email');
        $qq = $this->getParamInt('qq');
        $birth = $this->getParamString('birth');
        $sex = $this->getParamInt('sex');
        $mobile = $this->getParamInt( 'mobile');
        $userInfo = User_Info::userPowerRegister(  $qq, $birth, $sex, $mobile, $email);
        Helper_Url::redirect('index.php');
    }
 
}